package com.ioidea.holland.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;

public class StarTextView extends androidx.appcompat.widget.AppCompatTextView {

    public StarTextView(Context context) {
        this(context, null);
    }

    public StarTextView(Context context, AttributeSet attrs) {
        this(context, attrs, android.R.attr.text); // Attention here !
    }

    public StarTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);


    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        CharSequence content = getText().toString();
        if (!TextUtils.isEmpty(content) && !content.toString().endsWith("*")) {
            String tmp = content+"*";
            SpannableStringBuilder style = new SpannableStringBuilder(tmp);
            style.setSpan(new ForegroundColorSpan(Color.parseColor("#FF0000")), tmp.length() - 1,
                    tmp.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            setText(style);
        }

    }
}
